-- card: 33586 from stack: in.5 -- bmap block id: 9152 -- flags: 0000 -- background id: 3858 -- name: FileExists ----- HyperTalk script ----- on HideObjects hide cd btn "Try It!" end HideObjects on ShowObjects show cd btn "Try It!" end ShowObjects -- part 2 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp global errGlobal ask "Enter some full path name" if it = empty then exit mouseUp put fileExists(it,"nodialog:errGlobal") into itIsThere if last char of it = ":" then put "folder" into type else put "file" into type if itIsThere = "true" then answer "Good guess! That" && type && "exists!" else answer "Sorry, that" && type && "does not exist!" end if end mouseUp -- part contents for background part 38 ----- text ----- 16/50 -- part contents for background part 20 ----- text ----- FileExists - An XFCN to test whether or not a file/folder exists on a mounted volume. FileExists(pathname, «"noDialog:"errorGlobal») This XFCN returns TRUE or FALSE depending on whether or not the file/folder specified by Pathname is on a mounted volume. It is useful to check for things like preferences stacks which your stack needs to install. -- part contents for background part 42 ----- text ----- { FileExits(pathname «,"nodialog":errGlobal») } {} { XFCN to determin whether or not the specified file/folder } { exists. Makes no modifications to the file/folder. } { Returns TRUE if the file/folder exists and FALSE if it does } { not. Assumes a full pathName is give in the parameter } { PathName. } {} { Written by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by : Anup Murarka } { AppleLink : Skeptic } { modification history } { Date Initials Comments } { ---- ------ ------------------------------------------------------} { 8/16/89 akm first written } { 5/22/90 ec removed upper case converion for A/UX compatibility. } { Changed version to 1.1 } {} unit FileExists; interface uses HyperXCmd; procedure MAIN (paramPtr: XCmdPtr); implementation procedure FileExists (paramPtr: XCmdPtr); FORWARD; procedure MAIN (paramPtr: XCmdPtr); begin FileExists(paramPtr); end; procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean; { check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end { asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end; { asked for copyright info } end; { one parameter passed } end; { function } function getParams (paramPtr: XCmdPtr; var PathToFind: str255): boolean; var numParams: integer; inputCh, syntaxStr, copyRtStr: str255; begin getParams := true; syntaxStr := 'FileExists(pathname «, “noDialog”:errGlobal»)'; copyRtStr := '© 1989,1990 Apple Computer, Inc., v.1.1, by Anup Murarka'; if askedForHelp(paramPtr, syntaxStr, copyRtStr) then begin getParams := false; exit(getParams); end; numParams := paramPtr^.paramCount; if (numParams < 1) or (numParams > 2) then begin getParams := false; reportToUser(paramPtr, syntaxStr); exit(getParams); end; ZeroToPas(paramPtr, paramPtr^.Params[1]^, PathToFind); end; {GetParams} procedure FileExists (paramPtr: XCmdPtr); var getParamsOK: boolean; PathToFind: str255; paramBlock: CInfoPBRec; errorCode: OSErr; begin { fetch and validate the passed parameters} getParamsOK := getParams(paramPtr, PathToFind); if not (getParamsOK) then exit(FileExists); { initialize parameter block. Since PathToFind is a full pathname, no other field is needed} zeroBytes(paramPtr, @paramBlock, sizeOf(paramBlock)); paramBlock.ioNamePtr := @PathToFind; { get file/folder info} errorCode := PBGetCatInfo(@paramBlock, FALSE); if errorCode = noErr then paramPtr^.returnValue := pasToZero(paramPtr, 'TRUE') else if (errorCode = dirNFErr) or (errorCode = fnfErr) then paramPtr^.returnValue := pasToZero(paramPtr, 'FALSE') else begin paramPtr^.returnValue := pasToZero(paramPtr, 'FALSE'); reportToUser(paramPtr, 'Sorry, an unexpected error has occured'); end; end; { procedure FileExists} end. { unit FileExists}